package org.dtrd.modules.record.entity.po;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dtrd.common.util.DateUtils;
import org.dtrd.modules.record.entity.bean.SleepBean;

import javax.persistence.Column;
import java.text.ParseException;
import java.util.Date;


/**
 * <p>
 * 
 * </p>
 *
 * @author QR
 * @since 2021-11-05
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("dtrd_ent_rd_signin_sleep")
public class DtrdEntRdSigninSleep {


    @TableId(value = "data_id", type = IdType.AUTO)
    private Integer dataId;

    @TableField("patient_id")
    private Integer patientId;

    /**
     * 记录日期
     */
    @TableField("record_date")
    private Date recordDate;

    /**
     * 记录时间
     */
    @TableField("record_time")
    private Date recordTime;

    /**
     * 备注
     */
    @TableField("sleep_remark")
    private String sleepRemark;

    /**
     * 照片以 逗号 拼接
     */
    @Column(name = "record_photo")
    private String recordPhoto;

    /**
     * 睡眠状况, 1-正常, 2-早睡,3-晚睡,4-失眠
     */
    @TableField("sleep_status")
    private Integer sleepStatus;

    /**
     * 描述
     */
    @TableField("sleep_describe")
    private String sleepDescribe;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;

    /**
     * 记录类型, 0-打卡, 1-建档
     */
    @TableField("sleep_record_archive_tag")
    private Integer sleepRecordArchiveTag;

    @TableField("is_del")
    @TableLogic
    private Integer isDel;


    public DtrdEntRdSigninSleep init() {
        isDel = 0;
        createTime = new Date();
        return this;
    }

    public DtrdEntRdSigninSleep parseFromDTO(SleepBean dto){
        dataId = dto.getDataId();
        patientId = dto.getPatientId();
        if (StrUtil.isNotBlank(dto.getRecordTime())){
            try {
                recordDate = DateUtils.parseDate(dto.getRecordTime(), DateUtils.date_sdf.get().toPattern());
                recordTime = DateUtils.parseDate(dto.getRecordTime(), DateUtils.datetimeFormat.get().toPattern());
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        sleepRemark = dto.getSleepRemark();
        sleepStatus = dto.getSleepStatus();
        sleepDescribe = dto.getSleepDescribe();
        recordPhoto = dto.getRecordPhoto();
        return this;
    }
}
